﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DingY.DB;

namespace DotNet.WinUI.Admin
{
    public partial class FrmModPwd : BaseForm
    {
        public FrmModPwd()
        {
            InitializeComponent();
        }

        public FrmModPwd(string LoginID)
        {
            InitializeComponent();

            txtLoginID.Text = LoginID;
        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Name.ToLower())
            {
                case "save":
                    SaveData();
                    break;
                case "close":
                    Close();
                    break;
            }
        }

        private void SaveData()
        {
            string sql = @"SELECT COUNT(*) 
                FROM Users
                WHERE LoginID='{0}'
	                and Pwd ='{1}' ";
            sql = string.Format(sql,
                txtLoginID.Text,
                txtPwd.Text);
            SqlDB objSqlDB = new SqlDB();

            if (Convert.ToInt32(objSqlDB.ExecuteScalar(sql)) <= 0)
            {
                ShowMsg("原密码不正确，请重新输入密码！");
                return;
            }

            if (txtQuestionPwd.Text == txtNewPwd.Text)
            {
                sql = @"UPDATE Users 
                    SET Pwd = '{1}'
                    WHERE LoginID = '{0}' ";
                sql = string.Format(sql,
                    txtLoginID.Text,
                   txtNewPwd.Text);

                if (objSqlDB.ExecuteSql(sql) >= 1)
                {
                    ShowMsg("密码修改成功!");
                }
            }
            else
            {
                ShowMsg("新密码和确认密码不相符合，请重新输入密码！");
            }
        }

    }
}